﻿using System.IO;

namespace TeamsPortal.ServiceClient
{
    public interface IFileSystemProvider
    {
        void WriteAllBytes(string path, byte[] bytes);

        FileStream OpenRead(string path);

        void Delete(string path);
    }

    public class FileSystemProvider : IFileSystemProvider
    {
        public void WriteAllBytes(string path, byte[] bytes)
        {
            string dirPath = Path.GetDirectoryName(path);
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            File.WriteAllBytes(path, bytes);
        }


        public FileStream OpenRead(string path)
        {
            FileStream stream = File.OpenRead(path);
            return stream;
        }

        public void Delete(string path)
        {
            File.Delete(path);
        }
    }
}
